<template>
  <div>
    <h2 id="page-heading" data-cy="CityListHeading">
      <span id="city-list-heading">City Lists</span>
      <div class="d-flex justify-content-end">
        <button class="btn btn-info mr-2" v-on:click="handleSyncList" :disabled="isFetching">
          <font-awesome-icon icon="sync" :spin="isFetching"></font-awesome-icon> <span>Refresh List</span>
        </button>
        <router-link :to="{ name: 'CityListCreate' }" custom v-slot="{ navigate }">
          <button
            @click="navigate"
            id="jh-create-entity"
            data-cy="entityCreateButton"
            class="btn btn-primary jh-create-entity create-city-list"
          >
            <font-awesome-icon icon="plus"></font-awesome-icon>
            <span> Create a new City List </span>
          </button>
        </router-link>
      </div>
    </h2>
    <br />
    <div class="alert alert-warning" v-if="!isFetching && cityLists && cityLists.length === 0">
      <span>No cityLists found</span>
    </div>
    <div class="table-responsive" v-if="cityLists && cityLists.length > 0">
      <table class="table table-striped" aria-describedby="cityLists">
        <thead>
          <tr>
            <th scope="row"><span>ID</span></th>
            <th scope="row"><span>Location Id</span></th>
            <th scope="row"><span>Location Name</span></th>
            <th scope="row"><span>Country Name</span></th>
            <th scope="row"><span>Adm 1 Name</span></th>
            <th scope="row"><span>Adm 2 Name</span></th>
            <th scope="row"><span>Latitude</span></th>
            <th scope="row"><span>Longitude</span></th>
            <th scope="row"></th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="cityList in cityLists" :key="cityList.id" data-cy="entityTable">
            <td>
              <router-link :to="{ name: 'CityListView', params: { cityListId: cityList.id } }">{{ cityList.id }}</router-link>
            </td>
            <td>{{ cityList.locationId }}</td>
            <td>{{ cityList.locationName }}</td>
            <td>{{ cityList.countryName }}</td>
            <td>{{ cityList.adm1Name }}</td>
            <td>{{ cityList.adm2Name }}</td>
            <td>{{ cityList.latitude }}</td>
            <td>{{ cityList.longitude }}</td>
            <td class="text-right">
              <div class="btn-group">
                <router-link :to="{ name: 'CityListView', params: { cityListId: cityList.id } }" custom v-slot="{ navigate }">
                  <button @click="navigate" class="btn btn-info btn-sm details" data-cy="entityDetailsButton">
                    <font-awesome-icon icon="eye"></font-awesome-icon>
                    <span class="d-none d-md-inline">View</span>
                  </button>
                </router-link>
                <router-link :to="{ name: 'CityListEdit', params: { cityListId: cityList.id } }" custom v-slot="{ navigate }">
                  <button @click="navigate" class="btn btn-primary btn-sm edit" data-cy="entityEditButton">
                    <font-awesome-icon icon="pencil-alt"></font-awesome-icon>
                    <span class="d-none d-md-inline">Edit</span>
                  </button>
                </router-link>
                <b-button
                  v-on:click="prepareRemove(cityList)"
                  variant="danger"
                  class="btn btn-sm"
                  data-cy="entityDeleteButton"
                  v-b-modal.removeEntity
                >
                  <font-awesome-icon icon="times"></font-awesome-icon>
                  <span class="d-none d-md-inline">Delete</span>
                </b-button>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <b-modal ref="removeEntity" id="removeEntity">
      <span slot="modal-title"
        ><span id="roomAdminApp.cityList.delete.question" data-cy="cityListDeleteDialogHeading">Confirm delete operation</span></span
      >
      <div class="modal-body">
        <p id="jhi-delete-cityList-heading">Are you sure you want to delete this City List?</p>
      </div>
      <div slot="modal-footer">
        <button type="button" class="btn btn-secondary" v-on:click="closeDialog()">Cancel</button>
        <button
          type="button"
          class="btn btn-primary"
          id="jhi-confirm-delete-cityList"
          data-cy="entityConfirmDeleteButton"
          v-on:click="removeCityList()"
        >
          Delete
        </button>
      </div>
    </b-modal>
  </div>
</template>

<script lang="ts" src="./city-list.component.ts"></script>
